//
//  LoginInfoController.m
//  Shengzhuli
//
//  Created by FXGuo on 2017/9/5.
//  Copyright © 2017年 kamangkeji. All rights reserved.
//

#import "LoginInfoController.h"
#import "LoginRegisterService.h"
#import "MBProgressHUD+MJ.h"
#import "SZLAccountHelper.h"

@interface LoginInfoController ()

@property (weak, nonatomic) IBOutlet UITextField *nameField;
@property (weak, nonatomic) IBOutlet UITextField *idenField;

@end

@implementation LoginInfoController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"让别人认识你";
    self.view.backgroundColor = RGBColor(239, 239, 244);
}
- (IBAction)fieldChaged:(UITextField *)btn
{
    
}

- (IBAction)commitClick:(UIButton *)btn
{
    if (self.nameField.text.length<1) {
        [MBProgressHUD showError:@"请输入名字"];
        return;
    }
    if (self.idenField.text.length<1) {
        [MBProgressHUD showError:@"请输入职位"];
        return;
    }
    NSMutableDictionary *parame = [NSMutableDictionary dictionary];
    parame[@"name"] = self.nameField.text;
    parame[@"mobilePhone"] = [SZLAccountHelper shareInstance].mobilePhone;
    parame[@"position"] = self.idenField.text;
    [self showWaiter];
    [LoginRegisterService writeInfoWithParame:parame response:^(BOOL success, NSString *msg, NSString *token) {
        [self hideWaiter];
        if (success) {
            NSMutableDictionary *dict = [NSMutableDictionary dictionary];
            dict[@"token"] = token;
            dict[@"roleId"] = @([SZLAccountHelper shareInstance].roleId);
            dict[@"HXpwd"] = [SZLAccountHelper shareInstance].HXpwd;
            dict[@"mobilePhone"] = [SZLAccountHelper shareInstance].mobilePhone;
            [SZLAccountHelper updateUserWithLogin:dict needSave:YES];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self dismissViewControllerAnimated:YES completion:nil];
            });
        }else {
            [MBProgressHUD showError:msg];
        }
    }];
}


@end
